using System;
using System.Globalization;
using Avalonia.Data.Converters;

namespace AnimationPage.Converters;

public sealed class TimeToDisplayTimeConverter : IValueConverter
{
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is not DateTimeOffset time)
            return null;
        
        // If it is today...
        return time.ToLocalTime().ToString(time.Date == DateTimeOffset.UtcNow.Date ?
            // Return just time
            "HH:mm" : "HH:mm, dd MMM yyyy");

        // Otherwise, return a full date
    }

    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}